#include "DictSever.hpp"
#include "Dictionary.hpp"
#include<iostream>

void Usage(std::string proc)
{
    std::cerr << "Usage:" << proc << "+ severport" << std::endl; 
}

//./udpsever severport
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }
    EnableConsoleLogStrategy();
    //获取输入的port
    uint16_t port = std::stoi(argv[1]);
    //链接获取dict.txt中的数据信息
    Dictionary dict("./dict.txt");
    std::unique_ptr<DictSever> usv = std::make_unique<DictSever>(port,
        [&dict](const std::string &word, const std::string &clintip, uint16_t clintport)->std::string{
            return dict.Translate(word, clintip, clintport);
        });
    usv->Init();
    usv->Start();

    return 0;
}